home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / global.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-27  |  7.4 KB  |  286 lines

  1. #ifndef _GLOBAL_H
  2. #define    _GLOBAL_H
  3.  
  4. /* Global definitions used by every source file.
  5.  * Some may be compiler dependent.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #if    defined(__TURBOC__) || defined(__STDC__) || defined(LATTICE)
  13. #define    ANSIPROTO    1
  14. #endif
  15.  
  16. /* Distinguish between Turbo C 2.0, and Borland C++ 2.0,3.0,3.1 */
  17. #if defined(__TURBOC__) && defined(__BORLANDC__)
  18. #define DFAR far
  19. #else
  20. #define DFAR
  21. #endif
  22.  
  23. #ifndef    __ARGS
  24. #ifdef    ANSIPROTO
  25. #define    __ARGS(x)    x
  26. #else
  27. #define    __ARGS(x)    ()
  28. #endif
  29. #endif
  30.  
  31.  
  32. #if    !defined(AMIGA) && (defined(LATTICE) || defined(MAC) || defined(__TURBOC__))
  33. /* These compilers require special open modes when reading binary files.
  34.  *
  35.  * "The single most brilliant design decision in all of UNIX was the
  36.  * choice of a SINGLE character as the end-of-line indicator" -- M. O'Dell
  37.  *
  38.  * "Whoever picked the end-of-line conventions for MS-DOS and the Macintosh
  39.  * should be shot!" -- P. Karn's corollary to O'Dells' declaration
  40.  */
  41. #define    READ_BINARY    "rb"
  42. #define    WRITE_BINARY    "wb"
  43. #define    APPEND_BINARY    "ab+"
  44. #define    READ_TEXT    "rt"
  45. #define    WRITE_TEXT    "wt"
  46. #define    APPEND_TEXT    "at+"
  47. #define UPDATE_TEXT    "rt+"
  48. #define CREATE_TEXT    "wt+"
  49.  
  50. #else
  51.  
  52. #define    READ_BINARY    "r"
  53. #define    WRITE_BINARY    "w"
  54. #define    APPEND_BINARY    "a+"
  55. #define    READ_TEXT    "r"
  56. #define    WRITE_TEXT    "w"
  57. #define    APPEND_TEXT    "a+"
  58. #define UPDATE_TEXT    "r+"
  59. #define CREATE_TEXT    "w+"
  60.  
  61. #endif
  62.  
  63. /* These two lines assume that your compiler's longs are 32 bits and
  64.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  65.  * but it doesn't matter if they're signed or unsigned.
  66.  */
  67. typedef long int32;        /* 32-bit signed integer */
  68. typedef unsigned short int16;    /* 16-bit unsigned integer */
  69. typedef unsigned char byte_t;    /*  8-bit unsigned integer */
  70. #define    uchar(x) ((unsigned char)(x))
  71. #define    MAXINT16 65535        /* Largest 16-bit integer */
  72. #define    MAXINT32 4294967295L    /* Largest 32-bit integer */
  73. #define    NBBY    8        /* 8 bits/byte */
  74.  
  75. #define    HASHMOD    7        /* Modulus used by hash_ip() function */
  76.  
  77. /* The "interrupt" keyword is non-standard, so make it configurable */
  78. #if    defined(__TURBOC__) && defined(MSDOS)
  79. #define    INTERRUPT    void interrupt
  80. #else
  81. #define    INTERRUPT    void
  82. #endif
  83.  
  84. /* Note that these definitions are on by default if none of the Turbo-C style
  85.  * memory model definitions are on; this avoids having to change them when
  86.  * porting to 68K environments.
  87.  */
  88. #if    !defined(__TINY__) && !defined(__SMALL__) && !defined(__MEDIUM__)
  89. #define    LARGEDATA    1
  90. #endif
  91.  
  92. #if    !defined(__TINY__) && !defined(__SMALL__) && !defined(__COMPACT__)
  93. #define    LARGECODE    1
  94. #endif
  95.  
  96. /* Since not all compilers support structure assignment, the ASSIGN()
  97.  * macro is used. This controls how it's actually implemented.
  98.  */
  99. #ifdef    NOSTRUCTASSIGN    /* Version for old compilers that don't support it */
  100. #define    ASSIGN(a,b)    memcpy((char *)&(a),(char *)&(b),sizeof(b));
  101. #else            /* Version for compilers that do */
  102. #define    ASSIGN(a,b)    ((a) = (b))
  103. #endif
  104.  
  105. /* Define null object pointer in case stdio.h isn't included */
  106. #ifndef    NULL
  107. /* General purpose NULL pointer */
  108. #define    NULL (void *)0
  109. #endif
  110. #define    NULLCHAR (char *)0    /* Null character pointer */
  111. #define    NULLCHARP (char **)0    /* Null character pointer pointer */
  112. #define    NULLINT    (int *)0    /* Null integer pointer */
  113. #define    NULLFP     (int (*)())0    /* Null pointer to function returning int */
  114. #define    NULLVFP     (void (*)())0    /* Null pointer to function returning void */
  115. #define    NULLVIFP (INTERRUPT (*)())0
  116. #define    NULLFILE (FILE *)0    /* Null file pointer */
  117.  
  118. /* standard boolean constants */
  119. #define FALSE 0
  120. #define TRUE 1
  121. #define NO 0
  122. #define YES 1
  123.  
  124. #define CTLA 0x1
  125. #define CTLB 0x2
  126. #define CTLC 0x3
  127. #define CTLD 0x4
  128. #define CTLE 0x5
  129. #define CTLF 0x6
  130. #define CTLG 0x7
  131. #define CTLH 0x8
  132. #define CTLI 0x9
  133. #define CTLJ 0xa
  134. #define CTLK 0xb
  135. #define CTLL 0xc
  136. #define CTLM 0xd
  137. #define CTLN 0xe
  138. #define CTLO 0xf
  139. #define CTLP 0x10
  140. #define CTLQ 0x11
  141. #define CTLR 0x12
  142. #define CTLS 0x13
  143. #define CTLT 0x14
  144. #define CTLU 0x15
  145. #define CTLV 0x16
  146. #define CTLW 0x17
  147. #define CTLX 0x18
  148. #define CTLY 0x19
  149. #define CTLZ 0x1a
  150.  
  151. #define    BELL    CTLG
  152. #define    BS    CTLH
  153. #define    TAB    CTLI
  154. #define    LF    CTLJ
  155. #define    FF    CTLL
  156. #define    CR    CTLM
  157. #define    XON    CTLQ
  158. #define    XOFF    CTLS
  159. #define    ESC    0x1b
  160. #define    DEL    0x7f
  161.  
  162. /* string equality shorthand */
  163. #define STREQ(x,y) (strcmp(x,y) == 0)
  164.  
  165. /* Extract a short from a long */
  166. #define    hiword(x)    ((int16)((x) >> 16))
  167. #define    loword(x)    ((int16)(x))
  168.  
  169. /* Extract a byte from a short */
  170. #define    hibyte(x)    ((unsigned char)((x) >> 8))
  171. #define    lobyte(x)    ((unsigned char)(x))
  172.  
  173. /* Extract nibbles from a byte */
  174. #define    hinibble(x)    (((x) >> 4) & 0xf)
  175. #define    lonibble(x)    ((x) & 0xf)
  176.  
  177. /* Various low-level and miscellaneous functions */
  178. unsigned long availmem __ARGS((void));
  179. void *callocw __ARGS((unsigned nelem,unsigned size));
  180. int32 clock();
  181. int dirps __ARGS((void));
  182. int getopt __ARGS((int argc,char *argv[],char *opts));
  183. int atoip __ARGS((char *));
  184. int htoi __ARGS((char *));
  185. long htol __ARGS((char *));
  186. char *inbuf __ARGS((int16 port,char *buf,int16 cnt));
  187. int16 hash_ip __ARGS((int32 addr));
  188. int istate __ARGS((void));
  189. void log __ARGS((int s,char *fmt, ...));
  190. int log2 __ARGS((int16 x));
  191. void *ltop __ARGS((long));
  192. void *mallocw __ARGS((unsigned nb));
  193. char *outbuf __ARGS((int16 port,char *buf,int16 cnt));
  194. long ptol __ARGS((void *));
  195. void restore __ARGS((int));
  196. void rflush __ARGS((void));
  197. void rip __ARGS((char *));
  198. char *smsg __ARGS((char *msgs[],unsigned nmsgs,unsigned n));
  199. int tprintf __ARGS((char *fmt,...));
  200. #if    !defined __TURBOC__
  201. char *strdup __ARGS((const char *));
  202. #endif
  203. int wildmat __ARGS((char *s,char *p,char **argv));
  204.  
  205. #ifdef TNOS_68K
  206. #include "osk.h"
  207. #endif
  208.  
  209. #ifdef    AZTEC
  210. #define    rewind(fp)    fseek(fp,0L,0);
  211. #endif
  212.  
  213. #if    defined(__TURBOC__) && defined(MSDOS)
  214. #define movblock(so,ss,do,ds,c)    movedata(ss,so,ds,do,c)
  215. #ifndef outportw
  216. #define outportw outport
  217. #endif
  218. #ifndef inportw
  219. #define inportw inport
  220. #endif
  221.  
  222. #else
  223.  
  224. /* General purpose function macros already defined in turbo C */
  225. #ifndef    min
  226. #define    min(x,y)    ((x)<(y)?(x):(y))    /* Lesser of two args */
  227. #endif
  228. #ifndef max
  229. #define    max(x,y)    ((x)>(y)?(x):(y))    /* Greater of two args */
  230. #endif
  231. #ifdef    MSDOS
  232. #define MK_FP(seg,ofs)    ((void far *) \
  233.             (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  234. #endif
  235. #endif    /* __TURBOC __ */
  236.  
  237. #ifdef    AMIGA
  238. /* super kludge de WA3YMH */
  239. #ifndef    fileno
  240. #include <stdio.h>
  241. #endif
  242. #define fclose(fp)    amiga_fclose(fp)
  243. extern int amiga_fclose __ARGS((FILE *));
  244. extern FILE *tmpfile __ARGS((void));
  245.  
  246. extern char *sys_errlist[];
  247. extern int errno;
  248. #endif
  249.  
  250. /* Externals used by getopt */
  251. extern int optind;
  252. extern char *optarg;
  253.  
  254. /* Threshold setting on available memory */
  255. extern int32 Memthresh;
  256.  
  257. /* System clock - count of ticks since startup */
  258. extern int32 Clock;
  259.  
  260. /* Various useful standard error messages */
  261. extern char Badhost[];
  262. extern char Badinterface[];
  263. extern char Existingiface[];
  264. extern char Nospace[];
  265. extern char Notval[];
  266. extern char Version[];
  267. extern char Nosversion[];
  268. extern char *Hostname;
  269.  
  270. /* Your system's end-of-line convention */
  271. extern char Eol[];
  272.  
  273. /* Your system OS - set in files.c */
  274. extern char System[];
  275.  
  276. extern void (*Gcollect[])();
  277.  
  278. /* I know this is cheating, but it definitely makes sure that
  279.  * each module has config.h included ! - WG7J
  280.  */
  281. #ifndef _CONFIG_H
  282. #include "config.h"
  283. #endif
  284.  
  285. #endif    /* _GLOBAL_H */
  286.